import 'package:flutter_oldman_health/utils/http_util.dart';

import 'constant.dart';

class MessageService {
  //获取存量聊天消息
  // memberId 聊天成员id
  static Future queryMessageList(
      String memberId, int currPage, int pageSize) async {
    var result = await HttpUtil.get(
        Constant.host +
            '/manager/medical/chat/${Constant.enterpriseId}/relevance/$memberId',
        queryParams: {"currPage": currPage, "pageSize": pageSize});
    return result;
  }

  // 发送消息
  // receiverId 接收人  content 内容  reminderTime 提醒时间；（2021.10.18添加，为了再次提醒用户）
  static Future sendMessage(
      String receiverId, String content, int reminderTime) async {
    var result = await HttpUtil.post(
        Constant.host + '/manager/medical/chat/${Constant.enterpriseId}',
        data: {
          "receiverId": receiverId,
          "content": content,
          "reminderTime": reminderTime
        });
    return result;
  }

  // 设置消息已读
  static Future setMemberMessageHasRead(List ids) async {
    var result = await HttpUtil.put(
      Constant.host +
          '/manager/medical/health/terminal/mqtt_message/${Constant.enterpriseId}/reads',
      data: ids,
    );
    return result;
  }

  //获取未读消息
  static Future queryMemberMessageUnRead(String memberId) async {
    String mId = "&senderId=$memberId";
    String url = Constant.host +
        "/manager/medical/health/terminal/mqtt_message/" +
        Constant.enterpriseId +
        "/page?read=0&msgType=memberAdd" +
        (memberId == null ? "" : mId);
    var result = await HttpUtil.get(url);
    return result;
  }

  static Future confirmFamilyAdd(String memberId) async {
    String url =
        "${Constant.host}/manager/medical/user/${Constant.enterpriseId}/confirm?memberId=$memberId";
    var result = await HttpUtil.get(url);
    return result;
  }
}
